package stemmer;

import java.text.Normalizer;

import org.tartarus.snowball.*;
public class TestStemmer {

	
	public TestStemmer() {
		
	}
	
	/**
	 * 
	 * @param lang - language of stemmer (in our case -french )
	 * @param word - a word to stem
	 * @return a stemmed word
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 */
	public static String stem(String lang, String word)
			throws ClassNotFoundException, InstantiationException,
			IllegalAccessException {

		Class stemClass = Class.forName("org.tartarus.snowball.ext." + lang
				+ "Stemmer");
		SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance();
		stemmer.setCurrent(word);
		stemmer.stem();
		String your_stemmed_word = stemmer.getCurrent();
		return norm(your_stemmed_word);
	}

	public static String norm (String s) {
		return Normalizer.normalize(s.toLowerCase().replaceAll("_", " ").trim(), Normalizer.Form.NFD).replaceAll("[\u0300-\u036F]", "");
	}

	
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

		TestStemmer t = new TestStemmer();
		System.out.println(TestStemmer.stem("french", "élève"));
	}


}
